TK!2
=v
#1
:n
n
:v
1000
:s
i
:c
duration of pause
=u
=l
#1
:n
xyz
:v
999999999
88888888
7777777
666666
55555
4444
333
22
1
E
=f
#1
:n
play
:c
Sort up and down and around
:t
Procedure
#2
:n
pause
:c
Delaying procedure
:t
Procedure
:p
n
#3
:n
Bsort
:c
Bubble sort
:t
Procedure
:i
L,k
#1
:n
play
:z
" This is a demonstration of procedural programming capability in TK Plus.
" Start the Direct Solver by pressing F9.  The only rule in the Rule Sheet
                        " calls this function 'play' which sorts the list xyz in ascending order, pauses, sorts xyz
start:                  " in ascending order, pauses, sorts xyz in descending order, and pauses again.
call Bsort('xyz,'up)    " order, and pauses again.  The cycle repeats over
call pause()            " and over.  It can be terminated only by Ctrl-Break
call Bsort('xyz,'down)  " (preferably during a 'pause').  The length of the
call pause()            " pause depends on the value of  n  assigned on the
goto start              " Variable Sheet and on the speed of your computer.
/E
E
#2
:n
pause
:z
for i=0 to n
next i
/E
E
#3
:n
Bsort
:z
" Notation:
" L - name of a list with numeric values to be sorted
" k - sorting order (k='up is interpreted as ascending,
"     anything else as descending)

" Description:
" Standard bubble sort algorithm.
" A paired (complex) variables assignment statement used 
" for swapping the list elements in the 4th statement.

k:= 2*(k='up) - 1
for j=length(L) to 2 step -1
   for i=1 to j-1
      if k*L[i]>k*L[i+1] then (L[i],L[i+1]):= (L[i+1],L[i])
   next i
next j
/E
E
=r
#1
:r
call play()
=p
=t
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
No
:a
Yes
:r
Yes
:h
No
:t
1
:n
No
:d
fig2
%Bf,f,0,0,0,1,0>f,0,1,4,1,0
%Ol,f,0,0,0,1,0>f,8,1,4,1,0
